package com.clps.algorithm.chapter08.二叉搜索树的下一个结点;

import com.clps.algorithm.chapter07.二叉树每层的最大值.TreeNode;

public class demo02 {
    public static void main(String[] args) {

    }

    public TreeNode inorderSuccessor(TreeNode root,TreeNode p){
        TreeNode cur = root;
        TreeNode result= null;
        while (cur!=null){
            if(cur.val>p.val){
                result = cur;
                cur = cur.left;
            }else{
                cur = cur.right;
            }
        }
        return  result;
    }
}
